package compare;


import java.util.Comparator;

class  AgeSec implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        if(o1.getAge()==o2.getAge()){
            return 0;
        }else if(o1.getAge()>o2.getAge()){
            return 1;
        }
        return -1;
    }
}
class  AgeDesc implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        if(o1.getAge()==o2.getAge()){
            return 0;
        }else if(o1.getAge()>o2.getAge()){
            return -1;
        }
        return 1;
    }
}
/**
 * @author shkstart
 * @create 2022-10-29-16:06
 */
//                  implements Comparable<Student>
public class Student {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
//    比较两个student对象是否相等，需要复写Object类的equals
//    @Override
//    public boolean equals(Object o){
//        if(this == o){
//            return true;
//        }
//        if(o==null||!(o instanceof Student)){
////            传入对象为空或不是student类型对象
//                    return false;
//        }
////        此时O一定不为空且是student对象，脱掉o的马甲
//        Student stu = (Student) o;
//        return this.name.equals(((Student) o).name);
//    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

//    @Override
//    public int compareTo(Student o) {
//        if (this.age == o.age) {
//            return 0;
//        } else if (this.age < o.age) {
//            return -1;
//        }
//        return 1;
//    }
}
